package com.ktgj.sms.common;

import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.common.sms.entity.RecvMoThread;
import com.ktgj.common.sms.service.CHttpPost;
import com.ktgj.sms.domain.Sms;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class MWSmsUtils {

    @Value("${MWSMS.ip}")
    private String ip;
    @Value("${MWSMS.port}")
    private String port;
    @Value("${MWSMS.userId}")
    private String userId;
    @Value("${MWSMS.userPass}")
    private String userPass;

    public boolean sendSmsInfo(Sms sms) {
        String SubPort = "*";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddmmss");
        String strUserMsgId = sdf.format(DateUtils.getNowDate());
        CHttpPost cHttpPost = new CHttpPost();
        StringBuffer stringBuffer = new StringBuffer();
        int response = cHttpPost.SendSms(stringBuffer, ip, port, userId, userPass, sms.getMobile(), sms.getSmsContent() + "【金色世纪】", SubPort, strUserMsgId, null, null, null, null, null, null, null, null, null);
        if (response == 0) {
            return true;
        }
        return false;
    }

    public void upMWSmsThread()
    {
        RecvMoThread thread = new RecvMoThread(ip, port, userId, userPass);
        thread.start();
    }

}
